home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / text / edit / vim60rt.lha / Vim / vim60 / doc / develop.txt < prev    next >
Encoding:
Text File  |  2001-09-26  |  12.9 KB  |  378 lines

  1. *develop.txt*   For Vim version 6.0.  Last change: 2001 Sep 03
  2.  
  3.  
  4.           VIM REFERENCE MANUAL    by Bram Moolenaar
  5.  
  6.  
  7. Development of Vim.                    *development*
  8.  
  9. This text is important for those who want to be involved in further developing
  10. Vim.
  11.  
  12. 1. Design goals        |design-goals|
  13. 2. Coding style        |coding-style|
  14. 3. Design decisions    |design-decisions|
  15. 4. Assumptions        |design-assumptions|
  16.  
  17. See the file README.txt in the "src" directory for an overview of the source
  18. code.
  19.  
  20. ==============================================================================
  21. 1. Design goals                        *design-goals*
  22.  
  23. Most important things come first (roughly).
  24.  
  25. Note that quite a few items are contradicting.  This is intentional.  A
  26. balance must be found between them.
  27.  
  28.  
  29. VIM IS... VI COMPATIBLE                    *design-compatible*
  30.  
  31. First of all, it should be possible to use Vim as a drop-in replacement for
  32. Vi.  When the user wants to, he can use Vim in compatible mode and hardly
  33. notice any difference with the original Vi.
  34.  
  35. Exceptions:
  36. - We don't reproduce obvious Vi bugs in Vim.
  37. - There are different versions of Vi.  I am using Version 3.7 (6/7/85) as a
  38.   reference.  But support for other versions is also included when possible.
  39.   The Vi part of POSIX is not considered a definitive source.
  40. - Vim adds new commands, you cannot rely on some command to fail because it
  41.   didn't exist in Vi.
  42. - Vim will have a lot of features that Vi doesn't have.  Going back from Vim
  43.   to Vi will be a problem, this cannot be avoided.
  44. - Some things are hardly ever used (open mode, sending an e-mail when
  45.   crashing, etc.).  Those will only be included when someone has a good reason
  46.   why it should be included and it's not too much work.
  47. - For some items it is debatable whether Vi compatibility should be
  48.   maintained.  There will be an option flag for these.
  49.  
  50.  
  51. VIM IS... IMPROVED                    *design-improved*
  52.  
  53. The IMproved bits of Vim should make it a better Vi, without becoming a
  54. completely different editor.  Extensions are done with a "Vi spirit".
  55. - Use the keyboard as much as feasible.  The mouse requires a third hand,
  56.   which we don't have.  Many terminals don't have a mouse.
  57. - When the mouse is used anyway, avoid the need to switch back to the
  58.   keyboard.  Avoid mixing mouse and keyboard handling.
  59. - Add commands and options in a consistent way.  Otherwise people will have a
  60.   hard time finding and remembering them.  Keep in mind that more commands and
  61.   options will be added later.
  62. - A feature that people do not know about is a useless feature.  Don't add
  63.   obscure features, or at least add hints in documentation that they exists.
  64. - Minimize using CTRL and other modifiers, they are more difficult to type.
  65. - There are many first-time and inexperienced Vim users.  Make it easy for
  66.   them to start using Vim and learn more over time.
  67. - There is no limit to the features that can be added.  Selecting new features
  68.   is one based on (1) what users ask for, (2) how much effort it takes to
  69.   implement and (3) someone actually implementing it.
  70.  
  71.  
  72. VIM IS... MULTI PLATFORM                *design-multi-platform*
  73.  
  74. Vim tries to help as many users on as many platforms as possible.
  75. - Support many kinds of terminals.  The minimal demands are cursor positioning
  76.   and clear-screen.  Commands should only use key strokes that most keyboards
  77.   have.  Support all the keys on the keyboard for mapping.
  78. - Support many platforms.  A condition is that there is someone willing to do
  79.   Vim development on that platform, and it doesn't mean messing up the code.
  80. - Support many compilers and libraries.  Not everybody is able or allowed to
  81.   install another compiler or GUI library.
  82. - People switch from one platform to another, and from GUI to terminal
  83.   version.  Features should be present in all versions, or at least in as many
  84.   as possible with a reasonable effort.  Try to avoid that users must switch
  85.   between platforms to accomplish their work efficiently.
  86. - That a feature is not possible on some platforms, or only possible on one
  87.   platform, does not mean it cannot be implemented.  [This intentionally
  88.   contradicts the previous item, these two must be balanced.]
  89.  
  90.  
  91. VIM IS... WELL DOCUMENTED                *design-documented*
  92.  
  93. - A feature that isn't documented is a useless feature.  A patch for a new
  94.   feature must include the documentation.
  95. - Documentation should be comprehensive and understandable.  Using examples is
  96.   recommended.
  97. - Don't make the text unnecessarily long.  Less documentation means that an
  98.   item is easier to find.
  99.  
  100.  
  101. VIM IS... HIGH SPEED AND SMALL IN SIZE            *design-speed-size*
  102.  
  103. Using Vim must not be a big attack on system resources.  Keep it small and
  104. fast.
  105. - Computers are becoming faster and bigger each year.  Vim can grow too, but
  106.   no faster than computers are growing.  Keep Vim usable on older systems.
  107. - Many users start Vim from a shell very often.  Startup time must be short.
  108. - Commands must work efficient.  The time they consume must be as small as
  109.   possible.  Useful commands may take longer.
  110. - Don't forget that some people use Vim over a slow connection.  Minimize the
  111.   communication overhead.
  112. - Items that add considerably to the size and are not used by many people
  113.   should be a feature that can be disabled.
  114. - Vim is a component among other components.  Don't turn it into a massive
  115.   application, but have it work well together with other programs.
  116.  
  117.  
  118. VIM IS... MAINTAINABLE                    *design-maintain*
  119.  
  120. - The source code should not become a mess.  It should be reliable code.
  121. - Use the same layout in all files to make it easy to read |coding-style|.
  122. - Use comments in a useful way!
  123. - Porting to another platform should be made easy, without having to change
  124.   too much platform-independent code.
  125. - Use the object-oriented spirit: Put data and code together.  Minimize the
  126.   knowledge spread to other parts of the code.
  127.  
  128.  
  129. VIM IS... FLEXIBLE                    *design-flexible*
  130.  
  131. Vim should make it easy for users to work in their preferred styles rather
  132. than coercing its users into particular patterns of work.  This can be for
  133. items with a large impact (e.g., the 'compatible' option) or for details.  The
  134. defaults are carefully chosen such that most users will enjoy using Vim as it
  135. is.  Commands and options can be used to adjust Vim to the desire of the user
  136. and its environment.
  137.  
  138.  
  139. VIM IS... NOT                        *design-not*
  140.  
  141. - Vim is not a shell or an Operating System.  You will not be able to run a
  142.   shell inside Vim or use it to control a debugger.  This should work the
  143.   other way around: Use Vim as a component from a shell or in an IDE.
  144.   A satirical way to say this: "Unlike Emacs, Vim does not attempt to include
  145.   everything but the kitchen sink, but some people say that you can clean one
  146.   with it.  ;-)"
  147. - Vim is not a fancy GUI editor that tries to look nice at the cost of
  148.   being less consistent over all platforms.  But functional GUI features are
  149.   welcomed.
  150.  
  151. ==============================================================================
  152. 2. Coding style                        *coding-style*
  153.  
  154. These are the rules to use when making changes to the Vim source code.  Please
  155. stick to these rules, to keep the sources readable and maintainable.
  156.  
  157. This list is not complete.  Look in the source code for more examples.
  158.  
  159.  
  160. MAKING CHANGES                        *style-changes*
  161.  
  162. The basic steps to make changes to the code:
  163. 1. Adjust the documentation.  Doing this first gives you an impression of how
  164.    your changes affect the user.
  165. 2. Make the source code changes.
  166. 3. Check ../doc/todo.txt if the change affects any listed item.
  167. 4. Make a patch with "diff -c" against the unmodified code and docs.
  168. 5. Make a note about what changed and include it with the patch.
  169.  
  170.  
  171. USE OF COMMON FUNCTIONS                    *style-functions*
  172.  
  173. Some functions that are common to use, have a special Vim version.  Always
  174. consider using the Vim version, because they were introduced with a reason.
  175.  
  176. NORMAL NAME    VIM NAME    DIFFERENCE OF VIM VERSION
  177. free()        vim_free()    Checks for freeing NULL
  178. malloc()    alloc()        Checks for out of memory situation
  179. malloc()    lalloc()    Like alloc(), but has long argument
  180. strcpy()    STRCPY()    Includes cast to (char *), for char_u * args
  181. strchr()    vim_strchr()    Accepts special characters
  182. strrchr()    vim_strrchr()    Accepts special characters
  183. isspace()    vim_isspace()    Can handle characters > 128
  184. iswhite()    vim_iswhite()    Only TRUE for Tab and space
  185. memcpy()    vim_memmove()    Handles overlapped copies
  186. bcopy()        vim_memmove()    Handles overlapped copies
  187. memset()    vim_memset()    Uniform for all systems
  188.  
  189.  
  190. NAMES                            *style-names*
  191.  
  192. Function names can not be more than 31 characters long (because of VMS).
  193.  
  194. Don't use "delete" as a variable name, C++ doesn't like it.
  195.  
  196. Because of the requirement that Vim runs on as many systems as possible, we
  197. need to avoid using names that are already defined by the system.  This is a
  198. list of names that are known to cause trouble.  The name is given as a regexp
  199. pattern.
  200.  
  201. is.*()        POSIX, ctype.h
  202. to.*()        POSIX, ctype.h
  203.  
  204. d_.*        POSIX, dirent.h
  205. l_.*        POSIX, fcntl.h
  206. gr_.*        POSIX, grp.h
  207. pw_.*        POSIX, pwd.h
  208. sa_.*        POSIX, signal.h
  209. mem.*        POSIX, string.h
  210. str.*        POSIX, string.h
  211. wcs.*        POSIX, string.h
  212. st_.*        POSIX, stat.h
  213. tms_.*        POSIX, times.h
  214. tm_.*        POSIX, time.h
  215. c_.*        POSIX, termios.h
  216. MAX.*        POSIX, limits.h
  217. __.*        POSIX, system
  218. _[A-Z].*    POSIX, system
  219. E[A-Z0-9]*    POSIX, errno.h
  220.  
  221. *_t        POSIX, for typedefs.  Use *_T instead.
  222.  
  223. wait        don't use as argument to a function, conflicts with types.h
  224. index        shadows global declaration
  225. time        shadows global declaration
  226. new        C++ reserved keyword
  227. try        Borland C++ doesn't like it to be used as a variable.
  228.  
  229. basename()    GNU string function
  230. dirname()    GNU string function
  231. get_env_value()    Linux system function
  232.  
  233.  
  234. VARIOUS                            *style-various*
  235.  
  236. Typedef'ed names should end in "_t": >
  237.     typdef int some_t;
  238. Define'ed names should be uppercase: >
  239.     #define SOME_THING
  240. Features always start with "FEAT_": >
  241.     #define FEAT_FOO
  242.  
  243. Don't use '\"', some compilers can't handle it.  '"' works fine.
  244.  
  245. Don't use:
  246.     #if HAVE_SOME
  247. Some compilers can't handle that and complain that "HAVE_SOME" is not defined.
  248. Use
  249.     #ifdef HAVE_SOME
  250. or
  251.     #if defined(HAVE_SOME)
  252.  
  253.  
  254. STYLE                            *style-examples*
  255.  
  256. General rule: One statement per line.
  257.  
  258. Wrong:        if (cond) a = 1;
  259.  
  260. OK:        if (cond)
  261.         a = 1;
  262.  
  263. Wrong:        while (cond);
  264.  
  265. OK:        while (cond)
  266.         ;
  267.  
  268. Wrong:        do a = 1; while (cond);
  269.  
  270. OK:        do
  271.         a = 1;
  272.         while (cond);
  273.  
  274.  
  275. Functions start with:
  276.  
  277. Wrong:    int function_name(int arg1, int arg2)
  278.  
  279. OK:    /*
  280.      * Explanation of what this function is used for.
  281.      *
  282.      * Return value explanation.
  283.      */
  284.         int
  285.     function_name(arg1, arg2)
  286.         int        arg1;        /* short comment about arg1 */
  287.         int        arg2;        /* short comment about arg2 */
  288.     {
  289.         int        local;        /* comment about local */
  290.  
  291.         local = arg1 * arg2;
  292.  
  293. NOTE: Don't use ANSI style function declarations.  A few people still have to
  294. use a compiler that doesn't support it.
  295.  
  296.  
  297. SPACES AND PUNCTUATION                    *style-spaces*
  298.  
  299. No space between a function name and the bracket:
  300.  
  301. Wrong:  func (arg);
  302. OK:    func(arg);
  303.  
  304. Do use a space after if, while, switch, etc.
  305.  
  306. Wrong:    if(arg)        for(;;)
  307. OK:    if (arg)    for (;;)
  308.  
  309. Use a space after a comma and semicolon:
  310.  
  311. Wrong:  func(arg1,arg2);    for (i = 0;i < 2;++i)
  312. OK:    func(arg1, arg2);    for (i = 0; i < 2; ++i)
  313.  
  314. Use a space before and after '=', '+', '/', etc.
  315.  
  316. Wrong:    var=a*5;
  317. OK:    var = a * 5;
  318.  
  319. In general: Use empty lines to group lines of code together.  Put a comment
  320. just above the group of lines.  This makes it more easy to quickly see what is
  321. being done.
  322.  
  323. OK:    /* Prepare for building the table. */
  324.     get_first_item();
  325.     table_idx = 0;
  326.  
  327.     /* Build the table */
  328.     while (has_item())
  329.         table[table_idx++] = next_item();
  330.  
  331.     /* Finish up. */
  332.     cleanup_items();
  333.     generate_hash(table);
  334.  
  335. ==============================================================================
  336. 3. Design decisions                    *design-decisions*
  337.  
  338. Folding
  339.  
  340. Several forms of folding should be possible for the same buffer.  For example,
  341. have one window that shows the text with function bodies folded, another
  342. window that shows a function body.
  343.  
  344. Folding is a way to display the text.  It should change the text itself.
  345. Therefore the folding has been implemented as a filter between the text stored
  346. in a buffer (buffer lines) and the text displayed in a window (logical lines).
  347.  
  348.  
  349. Naming the window
  350.  
  351. The word "window" is commonly used for several things: A window on the screen,
  352. the xterm window, a window inside Vim to view a buffer.
  353. To avoid confusion, other items that are sometimes called window have been
  354. given another name.  Here is an overview of the related items:
  355.  
  356. screen        The whole display.  For the GUI it's something like 1024x768
  357.         pixels.  The Vim shell can use the whole screen or part of it.
  358. shell        The Vim application.  This can cover the whole screen (e.g.,
  359.         when running in a console) or part of it (xterm or GUI).
  360. window        View on a buffer.  There can be several windows in Vim,
  361.         together with the command line, menubar, toolbar, etc. they
  362.         fit in the shell.
  363.  
  364.  
  365. To be continued...
  366.  
  367. ==============================================================================
  368. 4. Assumptions                        *design-assumptions*
  369.  
  370. Size of variables:
  371. char        8 bit signed
  372. char_u        8 bit unsigned
  373. int        16, 32 or 64 bit signed
  374. unsigned    16, 32 or 64 bit unsigned
  375. long        32 or 64 bit signed, can hold a pointer
  376.  
  377.  vim:tw=78:ts=8:ft=help:norl:
  378.